package server;

// TourServer.java
// Andrew Davison, April 2005, ad@fivedots.coe.psu.ac.th
/*
   The top-level Tour server, which waits for client connections
   and creates TourServerHandler threads to handle them.

   Details about each client are maintained in a TourGroup object
   which is referenced by each thread.

   Very similar to the multithreaded Chat server.
 */

import java.net.ServerSocket;
import java.net.Socket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Server
{

	final Logger logger = LoggerFactory.getLogger(Server.class);
	static final int PORT = 5555;

	private UserGroup userGroup;

	public Server()
	// wait for a client connection, spawn a thread, repeat
	{
		userGroup = new UserGroup();
		try {
			ServerSocket serverSock = new ServerSocket(PORT);
			Socket clientSock;

			while (true) {
				logger.info("Waiting for a client...");
				clientSock = serverSock.accept();
				new ServerHandler(clientSock, userGroup).start();
			}
		}
		catch(Exception e)
		{  System.out.println(e);  }
	}  // end of TourServer()


	// -----------------------------------

	public static void main(String args[]) 
	{  new Server();  }

} // end of TourServer class

